<%@ page session="false" %>
<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="javax.jcr.*, org.apache.sling.api.resource.Resource"%>
<%@ taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>
<%@ page trimDirectiveWhitespaces="true" %>
<sling:defineObjects />

<%
	response.setHeader("Cache-Control","max-age=3600");
	// Current node is of the chapter
	Node parent = currentNode.getParent();
	
	String id = currentNode.getProperty("sid").getValue().getString();
	String bookName = parent.getProperty("name").getValue().getString();
	String chapter = currentNode.getName();
	
	NodeIterator verses = currentNode.getNodes();
%>

{
	id: "<%=id%>", 
	book: "<%=bookName%>", 
	chapter: "<%=chapter %>", 
	
	verses: [
	<%
		while(verses.hasNext()){
			Node verse = verses.nextNode();
			String path = verse.getPath();
	%>
		<sling:include flush="true" path="<%=path%>"/>
	<%
			if(verses.hasNext()){
				%>,<%
			}
		}
	%>
	]
}